package com.oz.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.oz.entity.UserEntity;

@Mapper
public interface UserMapper extends BaseMapper<UserEntity> {



	@Select("<script>" 	
			+ "SELECT id,username,headimg,enabled,phone,address,birth FROM `BASIC_USER` " 
			+ 	"<if test = ' ew != null and ew.customSqlSegment != null '>  "
			+ 		"${ew.customSqlSegment} "
			+ 	"</if>"
//			
//			+ 	"<if test = ' tops != null and tops.length > 0 and tops[0].length != 0 '>"
//			+ 		"<if test = ' ew != null and ew.expression.orderBy.size() != 0  '>,</if>"
//			+ 		"<if test = ' ew != null and ew.expression.orderBy.size() == 0  '> ORDER BY </if>"
//			+ 		"<foreach item='topID' collection='tops[0]' open='' separator=',' close=''>"
//			+ 			"ID='${topID}' DESC"
//			+ 		"</foreach>"
//			+ 	"</if>"
			
			+ "</script>")
	@Results({ 
				@Result(property = "id", column = "id"),
				@Result(property = "roles", column = "{ user_id = ID }", one = @One(select = "com.oz.mapper.RoleMapper.selectByUserId", fetchType = FetchType.LAZY)),			
			})
//	@SelectProvider(type = DemoOrderBySqlBuilder.class,method="selectSql")
	<P extends IPage<UserEntity>> P selectPageWithRoles(P page, @Param("ew") Wrapper<UserEntity> queryWrapper,String[]... tops);

}

